package com.crm.service.impl.customerManager;

import com.crm.common.model.Enum.StatusCodeEnum;
import com.crm.dao.mapper.contactManager.ContactMapper;
import com.crm.dao.mapper.customMapper.customerManagerCustomMapper.CustomerPoolCustomMapper;
import com.crm.dao.mapper.customMapper.customerManagerCustomMapper.CustomerSendCodeCustomMapper;
import com.crm.dao.mapper.customMapper.customerManagerCustomMapper.ModificationRecordCustomMapper;
import com.crm.dao.mapper.customerManager.*;
import com.crm.model.entity.contactManager.Contact;
import com.crm.model.entity.customerManager.*;
import com.crm.model.entity.sys.UserAccount;
import com.crm.model.qo.customerManager.CustomerPoolQO;
import com.crm.model.qo.customerManager.SendCodeQO;
import com.crm.model.vo.cluePoolManager.UserCompanyVO;
import com.crm.model.vo.customerManager.*;
import com.crm.service.customerManager.CustomerPoolDbService;
import com.crm.service.customerManager.CustomerSendCodeDbService;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @ Author ：baijian
 * @ Date   ：2021/8/7 16:11
 */
@Service
public class CustomerSendCodeDbServiceImpl implements CustomerSendCodeDbService {


    @Autowired
    private CustomerSendCodeCustomMapper customerSendCodeCustomMapper;

    @Autowired
    private CustomerProductDetailExchangeCodeMapper customerProductDetailExchangeCodeMapper;

    @Autowired
    private CustomerProductDetailThroughTrainTaxMapper customerProductDetailThroughTrainTaxMapper;

    @Autowired
    private CustomerProductDetailMemberCardMapper customerProductDetailMemberCardMapper;

    @Autowired
    private CustomerProductDetailYunMapper customerProductDetailYunMapper;

    @Autowired
    private CustomerProductDetailRechargeCodeMapper customerProductDetailRechargeCodeMapper;

    @Autowired
    private CustomerProductDetailCouponMapper customerProductDetailCouponMapper;

    /**
     * 会员卡信息
     * @param sendCodeQO 发码参数
     * @return
     */
    @Override
    public List<DetailMemberCardVO> customerProductDetailMemberCardList(SendCodeQO sendCodeQO) {
        return customerSendCodeCustomMapper.customerProductDetailMemberCardList(sendCodeQO);
    }

    /**
     * 税法直通车
     * @param sendCodeQO 发码参数
     * @return
     */
    @Override
    public List<CustomerProductDetailThroughTrainTaxVO> customerProductDetailThroughTrainTaxList(SendCodeQO sendCodeQO) {
        return customerSendCodeCustomMapper.customerProductDetailThroughTrainTaxList(sendCodeQO);
    }

    /**
     * 兑换码信息
     * @param sendCodeQO 发码参数
     * @return
     */
    @Override
    public List<CustomerProductDetailExchangeCodeVO> customerProductDetailExchangeCodeList(SendCodeQO sendCodeQO) {
        return customerSendCodeCustomMapper.customerProductDetailExchangeCodeList(sendCodeQO);
    }

    /**
     * 云顾问卡信息
     * @param sendCodeQO 发码参数
     * @return
     */
    @Override
    public List<CustomerProductDetailYunVO> customerProductDetailYunList(SendCodeQO sendCodeQO) {
        return customerSendCodeCustomMapper.customerProductDetailYunList(sendCodeQO);
    }

    /**
     * 充值卡
     * @param sendCodeQO 发码参数
     * @return
     */
    @Override
    public List<CustomerProductDetailRechargeCodeVO> customerProductDetailRechargeCodeList(SendCodeQO sendCodeQO) {
        return customerSendCodeCustomMapper.customerProductDetailRechargeCodeList(sendCodeQO);
    }

    /**
     * 优惠劵
     * @param sendCodeQO 发码参数
     * @return
     */
    @Override
    public List<CustomerProductDetailCouponVO> customerProductDetailCouponList(SendCodeQO sendCodeQO) {
        return customerSendCodeCustomMapper.customerProductDetailCouponList(sendCodeQO);
    }

    /**
     * 兑换码通过订单id和产品
     * @param productOrderId 订单编号
     * @param finishOrderProductNum 产品号
     * @return
     */
    @Override
    public List<CustomerProductDetailExchangeCode> customerProductDetailExchangeCodeByProductCodeList(String productOrderId, String finishOrderProductNum) {
        CustomerProductDetailExchangeCodeExample customerProductDetailExchangeCodeExample = new CustomerProductDetailExchangeCodeExample();
        CustomerProductDetailExchangeCodeExample.Criteria criteria = customerProductDetailExchangeCodeExample.createCriteria();
        criteria.andProductOrderIdEqualTo(productOrderId);
        criteria.andFinishOrderProductNumEqualTo(finishOrderProductNum);
        criteria.andDeleteStatusEqualTo(Short.parseShort(String.valueOf(StatusCodeEnum.NORMAL_CODE.getState())));
        return customerProductDetailExchangeCodeMapper.selectByExample(customerProductDetailExchangeCodeExample);
    }

    /**
     * 税法直通车通过订单id和产品
     * @param productOrderId 订单编号
     * @param finishOrderProductNum 产品号
     * @return
     */
    @Override
    public List<CustomerProductDetailThroughTrainTax> customerProductDetailThroughTrainTaxByProductCodeList(String productOrderId, String finishOrderProductNum) {
        CustomerProductDetailThroughTrainTaxExample customerProductDetailThroughTrainTaxExample = new CustomerProductDetailThroughTrainTaxExample();
        CustomerProductDetailThroughTrainTaxExample.Criteria criteria = customerProductDetailThroughTrainTaxExample.createCriteria();
        criteria.andProductOrderIdEqualTo(productOrderId);
        criteria.andFinishOrderProductNumEqualTo(finishOrderProductNum);
        criteria.andDeleteStatusEqualTo(Short.parseShort(String.valueOf(StatusCodeEnum.NORMAL_CODE.getState())));
        return customerProductDetailThroughTrainTaxMapper.selectByExample(customerProductDetailThroughTrainTaxExample);

    }

    /**
     * 会员卡通过订单id和产品
     * @param productOrderId 订单编号
     * @param finishOrderProductNum 产品号
     * @return
     */
    @Override
    public List<CustomerProductDetailMemberCard> customerProductDetailMemberCardByProductCodeList(String productOrderId, String finishOrderProductNum) {
        CustomerProductDetailMemberCardExample customerProductDetailMemberCardExample = new CustomerProductDetailMemberCardExample();
        CustomerProductDetailMemberCardExample.Criteria criteria = customerProductDetailMemberCardExample.createCriteria();
        criteria.andProductOrderIdEqualTo(productOrderId);
        criteria.andFinishOrderProductNumEqualTo(finishOrderProductNum);
        criteria.andDeleteStatusEqualTo(Short.parseShort(String.valueOf(StatusCodeEnum.NORMAL_CODE.getState())));
        return customerProductDetailMemberCardMapper.selectByExample(customerProductDetailMemberCardExample);
    }

    /**
     * 云顾问卡通过订单id和产品
     * @param productOrderId 订单编号
     * @param finishOrderProductNum 产品号
     * @return
     */
    @Override
    public List<CustomerProductDetailYun> customerProductDetailYunByProductCodeList(String productOrderId, String finishOrderProductNum) {
        CustomerProductDetailYunExample customerProductDetailYunExample = new CustomerProductDetailYunExample();
        CustomerProductDetailYunExample.Criteria criteria = customerProductDetailYunExample.createCriteria();
        criteria.andProductOrderIdEqualTo(productOrderId);
        criteria.andFinishOrderProductNumEqualTo(finishOrderProductNum);
        criteria.andDeleteStatusEqualTo(Short.parseShort(String.valueOf(StatusCodeEnum.NORMAL_CODE.getState())));
        return customerProductDetailYunMapper.selectByExample(customerProductDetailYunExample);
    }

    /**
     * 充值卡通过订单id和产品
     * @param productOrderId 订单编号
     * @param finishOrderProductNum 产品号
     * @return
     */
    @Override
    public List<CustomerProductDetailRechargeCode> customerProductDetailRechargeCodeByProductCodeList(String productOrderId, String finishOrderProductNum) {
        CustomerProductDetailRechargeCodeExample customerProductDetailRechargeCodeExample = new CustomerProductDetailRechargeCodeExample();
        CustomerProductDetailRechargeCodeExample.Criteria criteria = customerProductDetailRechargeCodeExample.createCriteria();
        criteria.andProductOrderIdEqualTo(productOrderId);
        criteria.andFinishOrderProductNumEqualTo(finishOrderProductNum);
        criteria.andDeleteStatusEqualTo(Short.parseShort(String.valueOf(StatusCodeEnum.NORMAL_CODE.getState())));
        return customerProductDetailRechargeCodeMapper.selectByExample(customerProductDetailRechargeCodeExample);
    }

    /**
     * 优惠劵通过订单id和产品
     * @param productOrderId 订单编号
     * @param finishOrderProductNum 产品号
     * @return
     */
    @Override
    public List<CustomerProductDetailCoupon> customerProductDetailCouponByProductCodeList(String productOrderId, String finishOrderProductNum) {
        CustomerProductDetailCouponExample customerProductDetailCouponExample = new CustomerProductDetailCouponExample();
        CustomerProductDetailCouponExample.Criteria criteria = customerProductDetailCouponExample.createCriteria();
        criteria.andProductOrderIdEqualTo(productOrderId);
        criteria.andFinishOrderProductNumEqualTo(finishOrderProductNum);
        criteria.andDeleteStatusEqualTo(Short.parseShort(String.valueOf(StatusCodeEnum.NORMAL_CODE.getState())));
        return customerProductDetailCouponMapper.selectByExample(customerProductDetailCouponExample);
    }

    /**
     * 修改兑换码删除状态
     * @param vo 兑换码
     * @return
     */
    @Override
    public Boolean updateCustomerProductDetailExchangeCode(CustomerProductDetailExchangeCode vo) {
        Boolean result = false;
        int num = customerProductDetailExchangeCodeMapper.updateByPrimaryKeySelective(vo);
        if (num > 0) {
            result = true;
        }
        return result;
    }

    /**
     * 修改税法直通车删除状态
     * @param vo
     * @return
     */
    @Override
    public Boolean updateCustomerProductDetailThroughTrainTax(CustomerProductDetailThroughTrainTax vo) {
        Boolean result = false;
        int num = customerProductDetailThroughTrainTaxMapper.updateByPrimaryKeySelective(vo);
        if (num > 0) {
            result = true;
        }
        return result;
    }

    /**
     * 修改会员卡删除状态
     * @param vo
     * @return
     */
    @Override
    public Boolean updateCustomerProductDetailMemberCard(CustomerProductDetailMemberCard vo) {
        Boolean result = false;
        int num = customerProductDetailMemberCardMapper.updateByPrimaryKeySelective(vo);
        if (num > 0) {
            result = true;
        }
        return result;
    }

    /**
     * 修改云顾问卡卡删除状态
     * @param vo
     * @return
     */
    @Override
    public Boolean updateCustomerProductDetailYun(CustomerProductDetailYun vo) {
        Boolean result = false;
        int num = customerProductDetailYunMapper.updateByPrimaryKeySelective(vo);
        if (num > 0) {
            result = true;
        }
        return result;
    }

    /**
     * 修改充值卡删除状态
     * @param vo
     * @return
     */
    @Override
    public Boolean updateCustomerProductDetailRechargeCode(CustomerProductDetailRechargeCode vo) {
        Boolean result = false;
        int num = customerProductDetailRechargeCodeMapper.updateByPrimaryKeySelective(vo);
        if (num > 0) {
            result = true;
        }
        return result;
    }

    /**
     * 修改优惠劵删除状态
     * @param vo
     * @return
     */
    @Override
    public Boolean updateCustomerProductDetailCoupon(CustomerProductDetailCoupon vo) {
        Boolean result = false;
        int num = customerProductDetailCouponMapper.updateByPrimaryKeySelective(vo);
        if (num > 0) {
            result = true;
        }
        return result;
    }
}
